package servlet.user;

import dao.UserDao;
import dao.service.UserDaoImp;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import java.io.IOException;
import java.io.PrintWriter;

/**
 * @author cloudJiang
 * @date 2021/11/8 20:16
 */
@WebServlet("/userCodeCheck")
public class UserCodeCheck extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        //从用户输入页面中获取验证码
        String code = request.getParameter("validationCode");
        UserDao userDao = new UserDaoImp();
        PrintWriter out = response.getWriter();
        //从session中获取验证码
        HttpSession session = request.getSession();
        String validationCode = (String) session.getAttribute("randomCode");

        //check the validation code right or not
        if (validationCode.equals(code)) {
            out.write("true");
        } else {
            out.write("false");
        }

        out.close();
    }
}
